package Tarea3PanelY3Botones;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class CrearVentana extends JFrame implements ActionListener{
	private static CreaPanel panel=new CreaPanel();
	private static CrearVentana ventana;
	private JPanel panel2;
	private JButton boton1,boton2,boton3;
	public static boolean Sonido;
	private static int AumenVel=2;
	private static int AumenTam=2;
	
	
	
	
	public static void main (String[]arg){
		
		ventana = new CrearVentana();
		while (true){
			panel.moverBolita();
			panel.repaint();
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
	

	public CrearVentana() {
		super("Tarea 3");
		this.setLayout(new BorderLayout());		
		this.setSize(500,500);		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		AgregaVentana();

	}

	private void AgregaVentana() {
		CrearBotones();
		panel2 = CreaPanel(new FlowLayout());
		panel2.add(boton1);
		panel2.add(boton2);
		panel2.add(boton3);
		//this.add(panel2,BorderLayout.SOUTH);
		//this.add(panel,BorderLayout.CENTER);
		this.add("South",panel2);
		this.add("Center",panel);
		Sonido=false;
		
		boton1.addActionListener(this);
		boton2.addActionListener(this);
		boton3.addActionListener(this);
		
	}



	private void CrearBotones() {
		boton1=new JButton("Sonido on/off");
		boton2=new JButton("Velocidad");
		boton3=new JButton("tama�o");
		
	}



	private JPanel CreaPanel(FlowLayout flowL) {
		JPanel p = new JPanel();
		p.setLayout(flowL);
		p.setBackground(Color.GRAY);		
		return p;
		
	}



	@Override
	public void actionPerformed(ActionEvent act) {
		if(act.getSource() == boton1){	//activar o desactivar el sonido			
				
			 if(Sonido==false) 
			   Sonido=true;
			 else
				 Sonido=false;

		}else if (act.getSource()==boton2){//aumentar la velocidad
			for(int i=0;i<panel.n;i++){
				if(panel.Vx[i]<0)					
					panel.Vx[i]+=-AumenVel;
				else
					panel.Vx[i]+=AumenVel;
				
				if(panel.Vy[i]<0)
					panel.Vy[i]+=-AumenVel;
				else
					panel.Vy[i]+=AumenVel;
			}			
			
		}else if(act.getSource()==boton3){	//aumentar tama�o
			for(int i=0;i<panel.n;i++){
				panel.diam[i]+=AumenTam;				
			}			
		}

		
	}


	
	

}
